﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using imaginecup.util;
using Imaginecup.sprite;
using Imaginecup.sprite.animation;
using Imaginecup.util.resourceMan;
using Microsoft.Xna.Framework.Content;
using Imaginecup.shareData;
using Microsoft.Xna.Framework.Graphics;
using Imaginecup.gameState.intro;
using Imaginecup.scroll;
using Imaginecup.gameState.ending.scene5;
using Imaginecup.gameState.ending.scene5.unuse;

namespace Imaginecup.gameState.ending.unuse
{
    public class EndingScene5
    {
        enum State { State1, State2, State3 };

        private int m_InitY;

        private bool m_bInit;
        private bool m_bEnd;
        private bool m_bStart;
        
        private ContentManager m_ContentMan;

        private State m_State;

        private EndingScene5_1 m_Scene5_1;
        private EndingScene5_2 m_Scene5_2;
        private EndingScene5_3 m_Scene5_3;

        public EndingScene5()
        {

            m_InitY = 480 * 4;

            m_Scene5_1 = new EndingScene5_1();
            m_Scene5_2 = new EndingScene5_2(m_InitY);
            m_Scene5_3 = new EndingScene5_3(480 * 6);

            m_bInit = false;
            m_bEnd = false;
            m_bStart = false;

            m_State = State.State1;
        }



        public void LoadEndingScene()
        {
            m_bInit = true;

            m_ContentMan = new ContentManager(StateShareData.GetShareData().GetGame().Services);
            m_ContentMan.RootDirectory = "Content";

            for (int i = 1; i <= 14; i++)
            {
                ResourceMan.GetResourceMan().SetTextureFrame("" + i, m_ContentMan.Load<Texture2D>("ending\\5\\" + i));

            }

            m_Scene5_1.LoadEndingScene();
            m_Scene5_2.LoadEndingScene();
            m_Scene5_3.LoadEndingScene();
        }

        public void UnloadEndingScene()
        {
            m_Scene5_1.UnloadEndingScene();
            m_Scene5_2.UnloadEndingScene();
            m_Scene5_3.UnloadEndingScene();
        }

        public bool GetEnd()
        {
            return m_bEnd;
        }

        public void StartAnimation()
        {
            m_bStart = true;
            m_Scene5_1.StartAnimation();
        }

        public void Update(GameTime gameTime, ScrollMan scrollMan)
        {
            if (m_bEnd || !m_bStart) return;

            m_Scene5_1.Update(gameTime, scrollMan);
            m_Scene5_2.Update(gameTime, scrollMan);
            m_Scene5_3.Update(gameTime, scrollMan);

            if( scrollMan.GetCurrentStartPos().Y > 2200 && m_State == State.State1)
            {
                m_State = State.State2;
                m_Scene5_2.StartAnimation();
            }

            else if( scrollMan.GetCurrentStartPos().Y > 2500 && m_State == State.State2)
            {
                m_State = State.State3;
                m_Scene5_3.StartAnimation();
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            if (m_bEnd || !m_bInit) return;

            m_Scene5_1.Draw(spriteBatch);
            m_Scene5_2.Draw(spriteBatch);
            m_Scene5_3.Draw(spriteBatch);
        }

    }
}
